using System;
using System.Windows.Threading;
namespace Microsoft.Phone.Controls.Maps.Core
{
	internal class Timeout
	{
		private readonly Action action;
		private readonly DispatcherTimer timer = new DispatcherTimer();
		public Timeout(Action action, long timeout)
		{
			this.action = action;
			this.timer.add_Tick(new EventHandler(this.OnTimeout));
			this.timer.set_Interval(TimeSpan.FromTicks(timeout));
			this.timer.Start();
		}
		private void OnTimeout(object sender, EventArgs e)
		{
			this.action.Invoke();
			this.timer.remove_Tick(new EventHandler(this.OnTimeout));
			this.timer.Stop();
		}
		public void DoItNow()
		{
			if (this.timer.get_IsEnabled())
			{
				this.OnTimeout(this, null);
			}
		}
		public void Cancel()
		{
			this.timer.remove_Tick(new EventHandler(this.OnTimeout));
			if (this.timer.get_IsEnabled())
			{
				this.timer.Stop();
			}
		}
	}
}
